package io.renren.modules.oss.config;

import io.minio.MinioClient;
import io.renren.common.constant.Constant.CloudService;
import io.renren.common.utils.SpringContextUtils;
import io.renren.modules.oss.properties.OSSConfigProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: huan.xu
 * @create: 2023/12/23 15:20
 * @description:
 **/
@Configuration
public class MinioConfig {

  @Bean
  public MinioClient minioClient() {
    OSSConfigProperties ossConfigProperties = SpringContextUtils.getBean(OSSConfigProperties.class);
    if (ossConfigProperties.getCloudType() == CloudService.MINIO.getValue()) {
      return new MinioClient(
          ossConfigProperties.getMinio().getMinioEndpoint(),
          Integer.valueOf(ossConfigProperties.getMinio().getMinioPort()),
          ossConfigProperties.getMinio().getMinioAccessKey(),
          ossConfigProperties.getMinio().getMinioSecretKey(),
          ossConfigProperties.getMinio().getMinioSecure()
      );
    }
    return null;
  }
}
